package com.xayq.orap.mvc;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.xayq.orap.model.User;
import com.xayq.orap.service.ClientService;
import com.xayq.orap.service.ResourceService;
import com.xayq.orap.service.UserService;

@Controller
public class IndexControlller extends BaseController{
	
	@Autowired
	private ResourceService resourceService;
	
	@Autowired
	private ClientService clientService;
	
	@Autowired
	private UserService userService;
    /**
     * sitemesh模板页
     * @param request
     * @return
     */
    @RequestMapping(value = "/decorator", method = {RequestMethod.GET, RequestMethod.POST})
    public String decorator(HttpServletRequest request) {
        return "decorator";
    }
    
//    /**
//     * 默认主页
//     * @param request
//     * @return
//     */
//    @RequestMapping(value = "/index", method = {RequestMethod.GET, RequestMethod.POST})
//    public ModelAndView index(HttpServletRequest request) {
//        return getModelByUser();
//    }
//    
//    
//	/**
//     * 根据权限加载用户页面
//     * @return 
//     */
//    private ModelAndView getModelByUser() {
//    	UserDetails userDetails=getCurrentUserDetails();
//    	if(null!=userDetails){
//    		
//    		String userName = userDetails.getUsername();
//			//logger.debug("user: " + userName + " access");
//						          
//			ModelAndView mav = new ModelAndView("profile");
//			mav.addObject("userName", userName);
//            return mav;
//    	}else{
//    		return new ModelAndView("redirect:/login.jsp");
//    	}
//    }
    
    /**
     * 概况页
     * @param request
     * @return
     */
    @RequestMapping(value = "/profile", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView profile(HttpServletRequest request) {
    	int rsCount = resourceService.getTotalCount();
    	int clientCount = clientService.getTotalCount();
    	int userCount = userService.getTotalCount();
    	ModelAndView mav = new ModelAndView("profile");
        mav.addObject("rsCount", rsCount);
        mav.addObject("clientCount", clientCount);
        mav.addObject("userCount", userCount);
        return mav;
    }
//    
//    /**
//     * 资源管理页
//     * @param request
//     * @return
//     */
//    @RequestMapping(value = "/resources", method = {RequestMethod.GET, RequestMethod.POST})
//    public String resources(HttpServletRequest request) {
//        return "resources";
//    }
//    
//    /**
//     * 应用管理页
//     * @param request
//     * @return
//     */
//    @RequestMapping(value = "/apps", method = {RequestMethod.GET, RequestMethod.POST})
//    public String apps(HttpServletRequest request) {
//        return "apps";
//    }
//    
//    /**
//     * 用户管理页
//     * @param request
//     * @return
//     */
//    @RequestMapping(value = "/users", method = {RequestMethod.GET, RequestMethod.POST})
//    public String users(HttpServletRequest request) {
//        return "users";
//    }
    
    /**
     * 各分页
     * @param request
     * @return
     */
    @RequestMapping(value = "/{source}", method = {RequestMethod.GET, RequestMethod.POST})
    public String source(@PathVariable("source")String  source,HttpServletRequest request) {
        return source;
    }
}
